﻿@model IEnumerable<LotteryVoteMVC.Models.LotteryResult>
@using LotteryVoteMVC.Models
@using LotteryVoteMVC.Resources
@using LotteryVoteMVC.Utility
@{
    ViewBag.Title = @Resource.LotteryResult;
    Layout = "~/Views/Shared/Main.cshtml";
}
@section Header
{
    <script src="@Url.Content("~/Scripts/jquery.ui.datepicker.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.datepicker-" + CultureHelper.GetCurrentCulture() + ".js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/TableBase.css")" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function () {
            $("#Date").attr("readonly", "readonly").datepicker();
            $("#today").bind("click", function () {
                var today = new Date();
                $("#Date").datepicker("setDate", today);
                $("input[type='submit']").trigger("click")
            });
            $("#yesterday").bind("click", function () {
                var date = new Date();
                date.setDate(date.getDate() - 1);
                $("#Date").datepicker("setDate", date);
                $("input[type='submit']").trigger("click")
            });
        });
        var addResult = function (company,name) {
            buildFrame("addResult", 250, 800, "/Company/AddLotteryResult/{0}".format(company), "{0} {1}".format(resource.Add,name));
            $("#addResult").bind("load", function () {
                $("#addResult").contents().find("body").css("width", "780px");
            });
        }
    </script>
}
<div id="searchBar">
    @using (Html.BeginForm())
    {
        <span>@Resource.Time</span>
        @Html.TextBox("Date", Request["Date"] ?? DateTime.Today.ToShortDateString())
        <input type="submit" name="submit" id="submit" value="@Resource.Search" />
        <input type="button" name="today" id="today" value="@Resource.Today" />
        <input type="button" name="yesterday" id="yesterday" value="@Resource.Yesterday" />
    }
</div>
@foreach (var result in Model)
{
    int index = 1;
    <table style="width: 24%; float: left; margin: 5px; padding: 5px; vertical-align: middle;">
        <thead>
            <tr>
                <td colspan="2">
                    (@result.Company.Region.ToString().Substring(0, 1))@result.Company.Name
                    @if (ViewBag.CurrentUser.Role == Role.Company)
                    {
                        <span onclick="addResult(@result.Company.CompanyId,'@result.Company.Name')" title="@Resource.Edit" style="width:24px; height:24px; cursor:pointer; display:inline-block; background:url(@Url.Content("~/Content/Images/new.png"));">
                            &nbsp</span>
                    }
                </td>
            </tr>
        </thead>
        <tbody>
            @foreach (var record in result.Records)
            { 
                <tr>
                    <td style="width: 20%">
                        @(index++)
                    </td>
                    <td>
                        @(record == null ? string.Empty : record.Value)
                    </td>
                </tr>
            }
        </tbody>
    </table>
}